package cn.com.org.dao;

import java.util.List;
import java.util.Map;

import redis.clients.jedis.Jedis;

public class RedisUtil {

	public Jedis jedis;

	public RedisUtil() {
		jedis = RedisPoolBase.getJedis();		
		jedis.select(2);
	}

	public String getValue(String key) {
		String result = null;
		if (key == null || key.isEmpty()) {
			return result;
		}
		result = jedis.get(key);
		return result;
	}
	public List<String> getMapValue(String key,String... mapkey) {
		List<String> result=null;
		if(key==null||key.isEmpty()){
			return result;
		}
	    return	jedis.hmget(key, mapkey);
	}
	public Boolean setValue(String key,String value,int expire) {
		if (key == null || key.isEmpty()) {
			return false;
		}
	  String result=jedis.set(key, value);
	  if(expire>0){
		jedis.expire(key, expire*60);
	  }
		if(result.toLowerCase().equals("ok")){
			return true;
		}
		return false;
	}
	public Boolean setValue(String key,String value) {
		return setValue(key,value,1800000);
	}
	public Boolean setMapValue(String key, Map<String, String> map,int timeout) {
		if(key==null||key.isEmpty()){
			return false;
		}
	    String result=jedis.hmset(key, map);
	    jedis.expire(key, timeout);
	    if(result.toLowerCase().equals("ok")){
	    	return true;
	    }
		return false;
	}
	public Boolean setMapValue(String key, Map<String, String> map) {
		return setMapValue(key, map, 1800000);
		
	}
}
